package com.cjyd.hrjb.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.cjyd.hrjb.config.AdminConfig;
import org.springframework.stereotype.Component;

/**
 * Created fei wo by 2020/3/19
 */
@Component
public class JwtUtil {

    private AdminConfig adminConfig;

    public JwtUtil(AdminConfig adminConfig) {
        this.adminConfig = adminConfig;
    }

    public String generateToken(Long userId) {
        Algorithm algorithm = Algorithm.HMAC256(adminConfig.getJwtSecret());
        return JWT.create().withIssuer(adminConfig.getJwtIssuer())
                .withClaim("userId", userId)
                .sign(algorithm);
    }
}
